package com.huishu.goods.fegin.fallback;

import com.huishu.commons.pojo.Result;
import com.huishu.commons.pojo.dto.FindAvailableCouponDTO;
import com.huishu.commons.pojo.vo.CouponVO;
import com.huishu.goods.fegin.CouponFeignClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName：CouponFeignClientFallBack
 * @Author: ljj
 * @Date: 2023/4/10 14:30
 */
@Component
@Slf4j
public class CouponFeignClientFallBack implements FallbackFactory<CouponFeignClient> {

    @Override
    public CouponFeignClient create(Throwable throwable) {
        String msg = throwable == null ? "" : throwable.getMessage();
        if (!StringUtils.isEmpty(msg)) {
            log.error(msg);
        }
        return new CouponFeignClient() {
            @Override
            public Result<List<CouponVO>> findAvailableCoupon(FindAvailableCouponDTO findAvailableCouponDTO) {
                return Result.fail(msg);
            }

            @Override
            public Result<List<CouponVO>> findCouponByUserId(Long userId, List<Long> categoryId) {
                return Result.fail(msg);
            }

            @Override
            public Result<List<CouponVO>> findRepurchaseByUserId(Long userId, List<Long> categoryId) {
                return Result.fail(msg);
            }

            @Override
            public Result bindingCoupon(Long id, Long couponId) {
                return Result.fail(msg);
            }

            @Override
            public Result deleteCoupon(Long id, Long couponId) {
                return Result.fail(msg);
            }

            @Override
            public Result<List<CouponVO>> findCouponByProductIds(List<Long> ids) {
                return Result.fail(msg);
            }

        };
    }
}
